{include file="public/head"}
    <body class="index">
        <!-- 顶部开始 -->
       {include file="public/top_nav"}
        <!-- 顶部结束 -->
        <!-- 中部开始 -->
        <!-- 左侧菜单开始 -->
        {include file="public/left_nav"}
        <!-- 左侧菜单结束 -->
        <!-- 右侧主体开始 -->
        <div class="page-content">

        </div>
        <div class="page-content-bg"></div>
  <script>
  layui.use(['index','element'],function () {

    var $ = layui.jquery,element = layui.element;

    $.ajax({
      url:"index",
      type:"POST",
      dataType:"json",
      success:function (res) {
        console.log(res);
        //先添加所有的主材单
        $.each(res.data,function(i,obj){
          console.log(obj.status);
          if(obj.status == 0){
            return;
          }
          var content='<li class="layui-nav-item" data-name='+obj.action+'>';
        if (obj.children == undefined) {
          content+='<a href="'+'/'+obj.app+'/'+obj.controller+'/'+obj.action+'"><i class="layui-icon '+obj.icon+'"></i><cite>'+obj.name+'</cite></a>';
        }else{
          content+='<a href="javascript:;"><i class="layui-icon '+obj.icon+'"></i><cite>'+obj.name+'</cite></a>';
        }

          //这里是添加所有的子菜单
          content+=loadchild(obj);
          content+='</li>';
          $(".layui-nav-tree").append(content);
        });
        element.init();
      },error:function(jqXHR){
        alert("发生错误："+ jqXHR.status);
      }

    });


    //组装子菜单的方法
    function loadchild(obj){
      if(obj==null){
        return;
      }

      var content='';
      if(obj.children!=null && obj.children.length>0){
        content+='<dl class="layui-nav-child">';
      }else{
        content+='<dl>';
      }

      if(obj.children!=null && obj.children.length>0){
        $.each(obj.children,function(i,note){
          if(note.status==0){
            return;
          }
          content+='<dd>';
          content+='<a lay-href="'+'/'+note.app+'/'+note.controller+'/'+note.action+'">'+note.name+'</a>';
          if(note.children==null){
            return;
          }
          content+=loadchild(note);
          content+='</dd>';
        });

        content+='</dl>';
      }
      return content;
    }

  });
  </script>
        <!-- 右侧主体结束 -->
        <!-- 中部结束 -->
{include file="public/footer"}